// Color Container
// (c) jimon game studio

#ifndef JEH_JECOLOR
#define JEH_JECOLOR

#include "jeTypes.h"

namespace je
{
	namespace video
	{
		//! Color Container
		template<typename T>
		class jeColorARGB
		{
		public:
			//! Color Components
			T R,G,B,A;

			//! Constructor
			inline jeColorARGB()
				:R(0),G(0),B(0),A(0)
			{
			}

			//! Constructor
			inline jeColorARGB(T a,T r,T g,T b)
				:R(r),G(g),B(b),A(a)
			{
			}

			//! Constructor
			inline jeColorARGB(const jeColorARGB<T> & Other)
				:R(Other.R),G(Other.G),B(Other.B),A(Other.A)
			{
			}

			//! Destructor
			inline ~jeColorARGB()
			{
			}

			//! Convert to ARGB32f With Range
			jeColorARGB<f32> ConvertToRange(f32 OldMin,f32 OldMax,f32 NewMin,f32 NewMax) const
			{
				jeColorARGB<f32> color;
				color.A = (f32(A - OldMin) / f32(OldMax - OldMin)) * NewMax + NewMin;
				color.R = (f32(R - OldMin) / f32(OldMax - OldMin)) * NewMax + NewMin;
				color.G = (f32(G - OldMin) / f32(OldMax - OldMin)) * NewMax + NewMin;
				color.B = (f32(B - OldMin) / f32(OldMax - OldMin)) * NewMax + NewMin;
				return color;
			}

			//! Return true if color equal
			inline u1 equal(const jeColorARGB<T> & Other) const
			{
				if(Other.A == A && Other.R == R && Other.G == G && Other.B == B)
					return true;
				else
					return false;
			}

			//! operator ==
			inline u1 operator == (const jeColorARGB<T> & Other) const
			{
				return equal(Other);
			}

			//! operator !=
			inline u1 operator != (const jeColorARGB<T> & Other) const
			{
				return !equal(Other);
			}

			//! operator <
			inline u1 operator < (const jeColorARGB<T> & O) const
			{
				f64 Color1 = A * 256 * 256 * 256 + R * 256 * 256 + G * 256 + B;
				f64 Color2 = O.A * 256 * 256 * 256 + O.R * 256 * 256 + O.G * 256 + O.B;
				return Color1 < Color2;
			}

			//! operator >
			inline u1 operator > (const jeColorARGB<T> & O) const
			{
				f64 Color1 = A * 256 * 256 * 256 + R * 256 * 256 + G * 256 + B;
				f64 Color2 = O.A * 256 * 256 * 256 + O.R * 256 * 256 + O.G * 256 + O.B;
				return Color1 > Color2;
			}

			//! Set Color Values
			inline void SetColor(T a,T r,T g,T b)
			{
				A = a;
				R = r;
				G = g;
				B = b;
			}
		};

		//! Argb8
		typedef jeColorARGB<u8> jeColorARGB8;

		//! Argb32f
		typedef jeColorARGB<f32> jeColorARGB32f;
	}
}

#endif
